﻿using System;
using LiSAClient.LiSAService;
using LiSAClient.ServiceProvider;

namespace LiSAClient.Core.Services
{
    public class ReportService : BaseService
    {
        /// <summary>
        /// Generates and retreives an up-to-date MetaDataReport for the given project
        /// </summary>
        /// <param name="projectID">ID of the project</param>
        /// <returns>The report as a string</returns>
        public string GetProjectMetadataReport(Guid projectID)
        {
            var reportString = string.Empty;

            ServiceHandler.Instance.WithService(
                svc =>
                {
                    var metadataReportQuery = new MetadataReportQuery
                    {
                        ProjectID = projectID
                    };
                    var result = (MetadataReportQueryResult)svc.ExecuteQuery(metadataReportQuery);
                    if (result != null && result.ReportAsString != null)
                    {
                        reportString = result.ReportAsString;
                    }
                });
            return reportString;
        }

        /// <summary>
        /// Generates a full report as .CSV for import into spreadsheet software
        /// </summary>
        /// <param name="projectID">ID of the project to generate the report for</param>
        /// <returns>The report as a string</returns>
        public string GetFullProjectReport(Guid projectID)
        {
            var reportString = string.Empty;

            ServiceHandler.Instance.WithService(
                svc =>
                {
                    var query = new ExcelExportReportQuery
                    {
                        ProjectID = projectID
                    };
                    var result = (ExcelExportReportQueryResult)svc.ExecuteQuery(query);
                    if (result != null && result.ReportAsString != null)
                    {
                        reportString = result.ReportAsString;
                    }
                });
            return reportString;
        }
    }
}
